<?
/**
* Copyright (c) 2002-2007 BioWare Corp.
* http://www.bigdaddymonitor.org
*
* This file is part of the BigDaddy Monitoring
* program. It is free software distributed under
* the terms of the BSD License. It is ditributed
* in the hopes that it will be useful, but
* WITHOUT ANY WARRANTY; without event the implied
* warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE.
*
* The BSD License is available from:
* http://www.opensource.org/licenses/bsd-license.php
**/
/* --------------------------------------------------------------------------------------//
	BigDaddy Sessions
	copied from:
	BioBoards 3.0 Site Initialization
	Created: Duleepa Wijayawardhana, August 17, 2002
	Copyright 2003 BioWare Corp.
//--------------------------------------------------------------------------------------*/

//Functions are  a replacement for the php session functions.
//Best to read more about session functions at www.php.net
//DW

function sess_open($save_path, $session_name)	
{
	global $dbh;
	return true;
}

function sess_read($sessID) 
{
	$sql="SELECT value FROM sessions WHERE sessID='".$sessID."'";
	$result=db_query($sql);
	if ($result)
	{
		$sessdata=mysql_fetch_array($result);
		return $sessdata["value"];
	} 
	else 
	{
	    return(""); // Must return "" here.
	}

}

function sess_write($sessID, $val) 
{
	$sql="REPLACE INTO sessions SET value='".addslashes($val)."', created='".time()."', sessID='".$sessID."'";
	$result=db_query($sql);
	return true;
}

function sess_destroy($sessID) 
{

	$sql="DELETE FROM sessions WHERE sessID='".$sessID."'";
	$result=db_query($sql);
	if (mysql_errno()>0) 
	{
		return false;
	}
	else 
	{
		return true;
	}
	
}

function sess_gc($max_lifetime) 
{
	$sql="DELETE FROM sessions WHERE created < '".(time()-$max_lifetime)."'";
	$result=db_query($sql);
	if (mysql_errno()>0) 
	{
		return false;
	} 
	else 
	{
		return true;
	}
	
}

function sess_close() 
{
	return true;
}

session_set_save_handler ("sess_open", "sess_close", "sess_read", "sess_write", "sess_destroy", "sess_gc");


?>
